{extend name="property/public/insidePageBase" /}
{block name="title"}编辑管理员{/block}
{block name="body"}
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layui-form-pane">

            <div class="layui-row">
                <div class="layui-col-xs4" >
                    <div class="layui-form-item">
                        <label class="layui-form-label">职员工号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" value="{$info['number']??''}" lay-verify="require" autocomplete="off" placeholder="请输入工号" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs8" >
                    <div class="layui-form-item">
                        <label class="layui-form-label required">职工头像</label>
                        <div class="layui-input-inline">
                            <input type="text" name="avatar_url" value="{$info['avatar_url']??''}" placeholder="请上传个人头像" id="avatar_url" class="layui-input">
                        </div>
                        <img class="checkPictureByImg avatar_url" src="{$info['avatar_url']??''}" style="width: 80px;height: 40px;">
                        <div class="layui-input-inline layui-btn-container" style="width: auto;">
                            <button type="button" class="layui-btn layui-btn-primary uploadImg" lay-data="{field: 'avatar_url',data:{dir:'property/users', field:'avatar_url'}}">
                                <i class="layui-icon">&#xe67c;</i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-xs4" >
                    <div class="layui-form-item"><label class="layui-form-label indispensable">职工姓名</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" value="{$info['userInfo']['username']??''}" lay-verify="require" autocomplete="off" placeholder="请输入用户姓名" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs4">
                    <div class="layui-form-item"> <label class="layui-form-label indispensable">手机号码</label>
                        <div class="layui-input-block">
                            <input type="text" name="mobile"  value="{$info['userInfo']['mobile']??''}" lay-verify="require" autocomplete="off" placeholder="请输入手机号" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs4">
                    <div class="layui-form-item"> <label class="layui-form-label">邮箱账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="email" value="{$info['userInfo']['email']??''}" lay-verify="require" autocomplete="off" placeholder="请输入邮箱账号" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs4" >
                    <div class="layui-form-item"><label class="layui-form-label indispensable">登录账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="account" value="{$info['userInfo']['account']??''}" lay-verify="require" autocomplete="off" placeholder="请输入登录账号" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs4" >
                    <div class="layui-form-item">
                        <label class="layui-form-label">门禁密码</label>
                        <div class="layui-input-block">
                            <input type="text" name="guard_password"  value="{$info['guard_password']??''}" lay-verify="require"  autocomplete="off" placeholder="请输入门禁密码" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs4" >
                    <div class="layui-form-item">
                        <label class="layui-form-label">门禁卡号</label>
                        <div class="layui-input-block">
                            <input type="text" name="guard_card" value="{$info['guard_card']??''}" lay-verify="require"  autocomplete="off" placeholder="请输入门禁IC卡卡号" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs4" >
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">登陆密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="password" lay-verify="require" autocomplete="off" placeholder="请输入登陆密码" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6" >
                    <div class="layui-form-item">
                        <label class="layui-form-label">部门选择</label>
                        <div class="layui-input-block" id="group_data_show">
                        </div>
                    </div>
                </div>
                {if $addGroupAuth}
                <div class="layui-col-xs2" >
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-fluid addUserGroup"> 添加新部门 </button>
                </div>
                {/if}
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注说明</label>
                <div class="layui-input-block">
                    <textarea id="content" name="remark" placeholder="请输入备注说明" class="layui-textarea">{$info['remark']??''}</textarea>
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <button class="layui-btn" lay-submit lay-filter="submitBtn" id="submitBtn">提交</button>
            </div>
        </div>
    </div>
</div>
<script id="group_data_tpl" type="text/html">
    <input type="text" name="group_id" id="group-name" autocomplete="off" class="layui-input">
</script>
{/block} {block name="js"} {__block__}
<script>
    layui.use(['form', 'layer', 'layCascader', 'laytpl'], function() {
        var form = layui.form,  layer = layui.layer, $ = layui.$,layCascader = layui.layCascader, laytpl = layui.laytpl;
        $('.uploadImg').selectImages({
            confirm:function(res,elem,data) {
                $('#' + data.field).val(res[0].src);
                $('.' + data.field).attr('src',res[0].src)
            }
        });
        // 加载角色
        function loadGroupData() {
            $.get("{:request()->url()}", {get_type: 'getGroupData'}, function(res) {
                if(res.code !== 0) {
                    return layer.msg(res.msg)
                }
                var getTpl = document.getElementById('group_data_tpl').innerHTML; // 获取模板字符
                var elemView = document.getElementById('group_data_show'); // 视图对象
                // 渲染并输出结果
                laytpl(getTpl).render({}, function(str){
                    elemView.innerHTML = str;
                    layCascader({
                        elem: '#group-name',
                        clearable: true,
                        value: {$info['group_id']},
                        options: res.data
                    });
                });
            })
        }
        loadGroupData()
        $('.addUserGroup').on('click', function() {
            var url = '{:url("propertyGroupAdd")}';
            var index = parent.layer.open({title: '添加',type: 2,shade: 0.2, maxmin:true,area: ['500px', '450px'], content: url, btnAlign: 'c' , btn: ['确定', '取消'] , yes: function (index, layero) {
                    var iframeWindow = parent.window['layui-layer-iframe' + index] , submit = layero.find('iframe').contents().find("#submitBtn");
                    iframeWindow.layui.form.on('submit(submitBtn)', function (data) {
                        var field = data.field; //获取提交的字段
                        var loadAdd = parent.layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                        $.post(url, field, function (res) {
                            parent.layer.close(loadAdd);
                            if (res.code === 0) {
                                loadGroupData()
                                parent.layer.close(index); //关闭弹层
                                parent.layer.msg(res.msg, {icon: 6, offset: '15px'});
                            } else {
                                parent.layer.msg(res.msg, {icon: 5, offset: '15px'});
                            }
                        });
                    });
                    submit.trigger('click');
                }
            });
        });
        $(document).on('click','.addAuthRole', function() {
            var url = '{:url("propertyAuthRoleAdd")}';
            var index = parent.layer.open({title: '添加',type: 2,shade: 0.2, maxmin:true,area: ['500px', '80%'], content: url, btnAlign: 'c' , btn: ['确定', '取消'] , yes: function (index, layero) {
                    var iframeWindow = parent.window['layui-layer-iframe' + index] , submit = layero.find('iframe').contents().find("#submitBtn");
                    iframeWindow.layui.form.on('submit(submitBtn)', function (data) {
                        var field = data.field; //获取提交的字段
                        var loadAdd = parent.layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                        $.post(url, field, function (res) {
                            parent.layer.close(loadAdd);
                            if (res.code === 0) {
                                loadRoleList()
                                parent.layer.close(index); //关闭弹层
                                parent.layer.msg(res.msg, {icon: 6, offset: '15px'});
                            } else {
                                parent.layer.msg(res.msg, {icon: 5, offset: '15px'});
                            }
                        });
                    });
                    submit.trigger('click');
                }
            });
        });
    });
</script>
{/block}